#!/bin/sh

if [[ -z "$FG_JAVA_LIBS" ]]; then
    echo "FG_JAVA_LIBS is not set!";
    exit 1;
fi

SAXON_HOME_88_B="${FG_JAVA_LIBS}/com/saxonica/saxonb8-8-0-7j"
SAXON_HOME_88_SA="${FG_JAVA_LIBS}/com/saxonica/saxonsa8-8j"
SAXON_HOME_89_B="${FG_JAVA_LIBS}/com/saxonica/saxonb8-9-0-4j"
SAXON_HOME_89_SA="${FG_JAVA_LIBS}/com/saxonica/saxonsa8-9-0-4j"
SAXON_HOME_90_B="${FG_JAVA_LIBS}/com/saxonica/saxonb9-0-0-8j"
SAXON_HOME_90_SA="${FG_JAVA_LIBS}/com/saxonica/saxonsa9-0-0-8j"
SAXON_HOME_91_B="${FG_JAVA_LIBS}/com/saxonica/saxonb9-1-0-7j"
SAXON_HOME_91_SA="${FG_JAVA_LIBS}/com/saxonica/saxonsa9-1-0-7j"
SAXON_HOME_92_HE="${FG_JAVA_LIBS}/com/saxonica/saxonhe9-2-0-2j"
SAXON_HOME_92_PE="${FG_JAVA_LIBS}/com/saxonica/saxonpe9-2-0-2j"
SAXON_HOME_92_EE="${FG_JAVA_LIBS}/com/saxonica/saxonee9-2-0-2j"

xslt_std=java/transform/style.xsl
xslt_java=java/transform/using-java.xsl
xquery_std=java/transform/query.xq
xquery_java=java/transform/using-java.xq

if [[ -d "$SAXON_HOME_88_B" ]]; then
    echo "[**] Saxon 8.8 B is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_88_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_88_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_88_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_88_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 8.8 B is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_88_SA" ]]; then
    echo "[**] Saxon 8.8 SA is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_88_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_88_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_88_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_88_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 8.8 SA is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_89_B" ]]; then
    echo "[**] Saxon 8.9 B is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_89_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_89_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_89_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_89_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 8.9 B is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_89_SA" ]]; then
    echo "[**] Saxon 8.9 SA is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_89_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_89_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_89_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_89_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 8.9 SA is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_90_B" ]]; then
    echo "[**] Saxon 9.0 B is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_90_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_90_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_90_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_90_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.0 B is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_90_SA" ]]; then
    echo "[**] Saxon 9.0 SA is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_90_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_90_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_90_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_90_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.0 SA is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_91_B" ]]; then
    echo "[**] Saxon 9.1 B is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_91_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_91_B" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_91_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_91_B" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.1 B is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_91_SA" ]]; then
    echo "[**] Saxon 9.1 SA is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_91_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_91_SA" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_91_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_91_SA" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.1 SA is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_92_HE" ]]; then
    echo "[**] Saxon 9.2 HE is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_92_HE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_92_HE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_92_HE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_92_HE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.2 HE is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_92_PE" ]]; then
    echo "[**] Saxon 9.2 PE is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_92_PE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_92_PE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_92_PE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_92_PE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
    echo;
else
    echo "[**] Saxon 9.2 PE is not installed, it won't be tested...";
fi
echo
if [[ -d "$SAXON_HOME_92_EE" ]]; then
    echo "[**] Saxon 9.2 EE is gonna be tested...";
    SAXON_HOME="$SAXON_HOME_92_EE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_std};
    SAXON_HOME="$SAXON_HOME_92_EE" \
        saxon --b --repo=java/transform/repo/ -it main ${xslt_java};
    SAXON_HOME="$SAXON_HOME_92_EE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_std};
    SAXON_HOME="$SAXON_HOME_92_EE" \
        saxon --b --repo=java/transform/repo/ --xq ${xquery_java};
else
    echo "[**] Saxon 9.2 EE is not installed, it won't be tested...";
fi
